<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>客户中心 - 银行管理系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background-color: #f5f5f5;
        }
        .main-container {
            display: flex;
            min-height: 100vh;
        }
        .sidebar {
            width: 250px;
            background-color: #0d47a1;
            color: #fff;
            padding-top: 20px;
        }
        .sidebar .nav-link {
            color: #fff;
            padding: 10px 20px;
            border-left: 3px solid transparent;
        }
        .sidebar .nav-link:hover {
            background-color: #1565c0;
            border-left: 3px solid #fff;
        }
        .sidebar .nav-link.active {
            background-color: #1976d2;
            border-left: 3px solid #fff;
        }
        .sidebar .nav-link i {
            margin-right: 10px;
        }
        .content {
            flex: 1;
            padding: 20px;
            background-color: #fff;
        }
        .header {
            background-color: #1976d2;
            color: #fff;
            padding: 15px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .header h1 {
            margin: 0;
            font-size: 1.5rem;
        }
        .card {
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            margin-bottom: 20px;
        }
        .card-header {
            background-color: #1976d2;
            color: #fff;
            border-radius: 8px 8px 0 0 !important;
        }
    </style>
</head>
<body>
    <div class="main-container">
        <div class="sidebar">
            <div class="text-center mb-4">
                <h3>银行管理系统</h3>
            </div>
            <ul class="nav flex-column">
                <li class="nav-item">
                    <a class="nav-link active" href="/client/card/index">
                        <i class="fa fa-dashboard"></i> 控制台
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/balance">
                        <i class="fa fa-search"></i> 余额查询
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/deposit">
                        <i class="fa fa-plus-circle"></i> 存款
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/withdraw">
                        <i class="fa fa-minus-circle"></i> 取款
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/transfer">
                        <i class="fa fa-exchange"></i> 转账
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/transactions">
                        <i class="fa fa-list"></i> 交易记录
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/report-loss">
                        <i class="fa fa-lock"></i> 挂失/解挂
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/client/card/change-password">
                        <i class="fa fa-key"></i> 修改密码
                    </a>
                </li>
                <li class="nav-item mt-5">
                    <a class="nav-link" href="/">
                        <i class="fa fa-sign-out"></i> 退出系统
                    </a>
                </li>
            </ul>
        </div>
        
        <div class="flex-grow-1 d-flex flex-column">
            <div class="header">
                <h1>客户中心</h1>
                <div class="d-flex align-items-center">
                    <span>欢迎，客户</span>
                </div>
            </div>
            
            <div class="content">
                <div id="alertContainer"></div>
                
                <div class="row">
                    <div class="col-md-4">
                        <div class="card">
                            <div class="card-header">
                                <h5 class="mb-0">快捷操作</h5>
                            </div>
                            <div class="card-body">
                                <div class="list-group">
                                    <a href="/client/card/deposit" class="list-group-item list-group-item-action">
                                        <i class="fa fa-plus-circle text-success mr-2"></i> 存款
                                    </a>
                                    <a href="/client/card/withdraw" class="list-group-item list-group-item-action">
                                        <i class="fa fa-minus-circle text-danger mr-2"></i> 取款
                                    </a>
                                    <a href="/client/card/transfer" class="list-group-item list-group-item-action">
                                        <i class="fa fa-exchange text-primary mr-2"></i> 转账
                                    </a>
                                    <a href="/client/card/balance" class="list-group-item list-group-item-action">
                                        <i class="fa fa-search text-info mr-2"></i> 余额查询
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-md-8">
                        <div class="card">
                            <div class="card-header">
                                <h5 class="mb-0">银行卡信息</h5>
                            </div>
                            <div class="card-body">
                                <div class="form-group">
                                    <label for="cardId">请输入卡号</label>
                                    <div class="input-group">
                                        <input type="text" class="form-control" id="cardId" placeholder="请输入银行卡号">
                                        <div class="input-group-append">
                                            <button class="btn btn-primary" id="queryBtn">查询</button>
                                        </div>
                                    </div>
                                </div>
                                
                                <div id="cardInfo" style="display: none;">
                                    <div class="card bg-light">
                                        <div class="card-body">
                                            <h5 class="card-title" id="cardTitle">银行卡信息</h5>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <p><strong>卡号：</strong> <span id="cardIdDisplay"></span></p>
                                                    <p><strong>客户姓名：</strong> <span id="customerName"></span></p>
                                                    <p><strong>存款类型：</strong> <span id="savingName"></span></p>
                                                </div>
                                                <div class="col-md-6">
                                                    <p><strong>余额：</strong> <span id="balance"></span> 元</p>
                                                    <p><strong>状态：</strong> <span id="status"></span></p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="card mt-4">
                            <div class="card-header">
                                <h5 class="mb-0">最近交易记录</h5>
                            </div>
                            <div class="card-body">
                                <div id="noCard" class="text-center py-3">
                                    请先查询银行卡信息
                                </div>
                                <div id="transactionList" style="display: none;">
                                    <table class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>交易时间</th>
                                                <th>交易类型</th>
                                                <th>交易金额</th>
                                                <th>备注</th>
                                            </tr>
                                        </thead>
                                        <tbody id="transactionBody">
                                        </tbody>
                                    </table>
                                    <div class="text-right">
                                        <a href="/client/card/transactions" class="btn btn-sm btn-primary">查看更多</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 通用提示框
        function showAlert(message, type) {
            const alertDiv = $('<div class="alert alert-' + type + ' alert-dismissible fade show" role="alert">' +
                message +
                '<button type="button" class="close" data-dismiss="alert" aria-label="Close">' +
                '<span aria-hidden="true">&times;</span>' +
                '</button>' +
                '</div>');
            
            $('#alertContainer').append(alertDiv);
            
            setTimeout(function() {
                alertDiv.alert('close');
            }, 3000);
        }
        
        $(document).ready(function() {
            // 查询银行卡信息
            $('#queryBtn').click(function() {
                const cardId = $('#cardId').val().trim();
                if (!cardId) {
                    showAlert('请输入银行卡号', 'warning');
                    return;
                }
                
                $.ajax({
                    url: '/client/card/query-balance',
                    type: 'GET',
                    data: { cardId: cardId },
                    success: function(res) {
                        if (res.code === 200) {
                            const card = res.data;
                            $('#cardIdDisplay').text(card.cardId);
                            $('#customerName').text(card.customerName);
                            $('#savingName').text(card.savingName);
                            $('#balance').text(card.balance);
                            $('#status').text(card.isReportLoss === 'YES' ? '已挂失' : '正常');
                            $('#status').removeClass('text-success text-danger')
                                .addClass(card.isReportLoss === 'YES' ? 'text-danger' : 'text-success');
                            
                            $('#cardInfo').show();
                            $('#noCard').hide();
                            
                            // 加载交易记录
                            loadTransactions(cardId);
                        } else {
                            showAlert(res.message || '查询失败', 'danger');
                        }
                    }
                });
            });
            
            // 加载交易记录
            function loadTransactions(cardId) {
                $.ajax({
                    url: '/client/card/query-transactions',
                    type: 'GET',
                    data: { cardId: cardId },
                    success: function(res) {
                        if (res.code === 200) {
                            const transactions = res.data;
                            let html = '';
                            
                            if (transactions && transactions.length > 0) {
                                // 只显示最近5条记录
                                const recentTransactions = transactions.slice(0, 5);
                                
                                recentTransactions.forEach(function(item) {
                                    html += '<tr>';
                                    html += '<td>' + formatDate(item.tradeDate) + '</td>';
                                    html += '<td>' + item.tradeType + '</td>';
                                    html += '<td>' + item.tradeMoney + '</td>';
                                    html += '<td>' + (item.remark || '') + '</td>';
                                    html += '</tr>';
                                });
                            } else {
                                html = '<tr><td colspan="4" class="text-center">暂无交易记录</td></tr>';
                            }
                            
                            $('#transactionBody').html(html);
                            $('#transactionList').show();
                        } else {
                            showAlert(res.message || '查询交易记录失败', 'danger');
                        }
                    }
                });
            }
            
            // 格式化日期
            function formatDate(dateString) {
                const date = new Date(dateString);
                const year = date.getFullYear();
                const month = String(date.getMonth() + 1).padStart(2, '0');
                const day = String(date.getDate()).padStart(2, '0');
                const hours = String(date.getHours()).padStart(2, '0');
                const minutes = String(date.getMinutes()).padStart(2, '0');
                const seconds = String(date.getSeconds()).padStart(2, '0');
                
                return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
            }
        });
    </script>
</body>
</html> 